/* ==============================================================================
 * 创 建 者：yqd
 * 创建日期：2017-11-02	
 * 功能描述：发邮件

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ===========================================================
 */

//发邮件
var SendLetterUrl = baseUrl + 'NoticeF/SendLetter';
//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';

var vu 
$(function(){
	initVue();
})
function initVue(){
	vu = new Vue({
	    el: '#content',
	    data: {
	    	member : '',
	    	target : 1,
			ToUserName : 'admin',
			Title : '',
			Body : '',
			imgurl:'',
	    },
	   mounted:function(){
	   	 this.getMemberView();
	   },
	    methods: {
	    	getMemberView : getMemberView,
			toUser : function(type){
				if(type==1){
					vu.ToUserName='';
				}else{
					vu.ToUserName='admin';
				}
			},
	        SendLetter: function () {
	        	var data = {
	        		ToUserName : vu.ToUserName,
	        		Title : vu.Title,
	        		Description : vu.Body,
	        		imgurl:vu.imgurl
	        	};
	        	
	    		if(!vu.ToUserName){
	    			mui.toast('请输入会员账号！');
	    			return;
	    		}
	        	
	        	if(!vu.Title){
	    			mui.toast('请输入邮件主题！');
	    			return;
	    		}
	        	if(!vu.Body){
	    			mui.toast('请输入邮件内容！');
	    			return;
	    		}
	            common.post(SendLetterUrl, data, 'json', function (r) {
	                if (r.ErrorCode == 0) {
	                    mui.confirm('发送成功,点击确定跳转至发件箱', '发送成功', ['是', '否'], function(e) {
		                    if (e.index == 0) {
		                        location.href = 'outbox.html';
		                    }else{
		                    	vu.Body = '';
		                    	vu.Title = '';
		                    	vu.ToUserName = vu.ToUserName == 'admin' ? 'admin' : '';
		                    }
		                })
	                } else {
	                    mui.toast(r.ErrorMsg);
	                }
	            })
	        }
	    }
	})
}

function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}


//上傳图片
function doUpload1() {

	var formData = new FormData();
	if ($(".upload1")[0].files.length == 0) {
		mui.toast("请选择图片！");
		return false;
	};
	formData.append("file", $(".upload1")[0].files[0]);
	formData.append("picTypeName", "USER_HEAD");
	$.ajax({
		url: baseUrl + "common/uploadimg",
		type: "POST",
		data: formData,
		async: false,
		cache: false,
		contentType: false,
		processData: false,
		success: function(r) {
			r = JSON.parse(r);
			var u = r.Data.url;
			if (r.ErrorCode == 0) {
				mui.toast("上传成功！");
				vu.imgurl = u;
			} else {
				mui.toast(r.ErrorMsg);
			}
		},
		error: function(returndata) {
			mui.toast("操作失败");
		}
	});
};